import Logger
import Schedule

class Task(hasDate):

    def __init__(self, name, duration, desc = '', worked = 0, due=None):

        self.name      = name
        self._duration = duration
        self._elapsed  = worked

        self.description = desc

        hasDate.__init__(self, due)

    def _get_remaining(self):
        return self._duration - self._elapsed

    def _get_elapsed(self):
        return self._elapsed

    def _get_duration(self):
        return self._duration

    def _set_duration(self, value):
        assert(value >= self.remaining)
        self._duration = value


    remaining = property(_get_remaining)
    duration  = property(_get_duration, _set_duration)
    elapsed   = property(_get_elapsed)


    def work(self, hours):

        assert(hours <= self.remaining)
        self._elapsed += hours

    def adjust(self, hours):

        assert(hours >= -self.remaining)
        self._duration += hours

    def __str__(self):

        str_rep = [
            "Name:           %s" % self.name,
            "Description:    %s" % self.description,
            "Estimated time: %s" % self.duration,
            "Time worked:    %s" % self.elapsed,
            "Time remaining: %s" % self.remaining
        ]
        
        return '\n'.join(str_rep)
                   

    
if __name__=='__main__':

    import doctest, Task
    doctest.testfile("test_task.txt")
